package com.iotteam.androidbase.moudules.test_sensor;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.iotteam.androidbase.R;
import com.iotteam.androidbase.base.ToolbarActivity;
import com.iotteam.androidbase.commen.network.Api;
import com.iotteam.androidbase.commen.network.core.HttpListener;
import com.iotteam.androidbase.commen.network.core.HttpManager;
import com.iotteam.androidbase.commen.utils.PLog;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lidechen on 5/5/17.
 */

public class TestSensorActivity extends ToolbarActivity {

    private static final String TAG = "TestSensorActivity";

    private Button mBindingBtn;
    private TextView mRecvText;
    private Button mClearBtn;
    private EditText mSendEdit;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_test_sensor;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mBindingBtn = (Button) findViewById(R.id.btn_binding);
        mClearBtn = (Button) findViewById(R.id.btn_clear);
        mRecvText = (TextView) findViewById(R.id.tv_recv);
        mSendEdit = (EditText) findViewById(R.id.et_send);

        mBindingBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                request();
            }
        });

        mClearBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mRecvText.setText("");
            }
        });
    }

    private void request(){
        /*Map<String, String> params = new HashMap<>();
        params.put("ip", "63.223.108.43");
        HttpManager.getInstance().getBean("http://ip.taobao.com/service/getIpInfo.php", params, TestBean.class, new HttpListener<TestBean>() {
            @Override
            public void onSucceed(int what, TestBean bean) {
                PLog.i(TAG, "onSucceed "+bean.getData().getCountry());

                mRecvText.setText(bean.toString());
            }

            @Override
            public void onFailed(int what, Exception e) {
                PLog.i(TAG, "onFailed ");
            }

            @Override
            public void onStart(int what) {
                PLog.i(TAG, "onStart ");
            }

            @Override
            public void onFinish(int what) {
                PLog.i(TAG, "onFinish ");
            }
        });*/

        /*mSendEdit.setText(Api.login);

        Map<String, String> params = new HashMap<>();
        params.put("mobile", "18686130461");
        params.put("password", "123456");
        //params.put("smscode", "4750");
        HttpManager.getInstance().postString(Api.login, params, new HttpListener<String>() {
            @Override
            public void onSucceed(int what, String bean) {
                PLog.i(TAG, "onSucceed "+bean);

                mRecvText.setText(bean);
            }

            @Override
            public void onFailed(int what, Exception e) {
                PLog.i(TAG, "onFailed ");
            }

            @Override
            public void onStart(int what) {
                PLog.i(TAG, "onStart ");
            }

            @Override
            public void onFinish(int what) {
                PLog.i(TAG, "onFinish ");
            }
        });*/

        String chinese = "http://suggest.taobao.com/sug?code=utf-8&q=卫衣&callback=cb";
        //String chinese2 = "http://47.93.60.227/bjteam/Api/MobileApi/test";
        //mSendEdit.setText(chinese2);//Api.sendVerifySMS

        String binding = Api.binding;
        mSendEdit.setText(binding);//Api.sendVerifySMS

        Map<String, String> params = new HashMap<>();
        params.put("terminalid", "865067020720534");
        params.put("password", "d326f5");
        params.put("moblie", "15910992968");

        HttpManager.getInstance().postString(binding, params, new HttpListener<String>() {
            @Override
            public void onSucceed(int what, String bean) {
                PLog.i(TAG, "onSucceed "+bean);

                mRecvText.setText(bean);
            }

            @Override
            public void onFailed(int what, Exception e) {
                PLog.i(TAG, "onFailed ");
            }

            @Override
            public void onStart(int what) {
                PLog.i(TAG, "onStart ");
            }

            @Override
            public void onFinish(int what) {
                PLog.i(TAG, "onFinish ");
            }
        });
    }

    public static void launch(Context context) {
        context.startActivity(new Intent(context, TestSensorActivity.class));
    }
}
